<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Examples</title>
  <meta name="description" content="">
  <meta name="keywords" content="">
  <link href="" rel="stylesheet">

  <script type="text/javascript" src="lib/vue.js"></script>
  <link rel="stylesheet" href="lib/swiper/css/swiper.css">
  <script src="lib/swiper/js/swiper.js"></script>

  <style>
    html,
    body {
      position: relative;
      height: 100%;
    }

    body {
      background: #eee;
      font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
      font-size: 14px;
      color: #000;
      margin: 0;
      padding: 0;
    }

    .swiper-container {
      width: 800px;
      height: 300px;
    }

    .swiper-slide {
      text-align: center;
      font-size: 18px;
      background: #fff;

      /* Center slide text vertically */
      display: -webkit-box;
      display: -ms-flexbox;
      display: -webkit-flex;
      display: flex;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-box-align: center;
      -ms-flex-align: center;
      -webkit-align-items: center;
      align-items: center;
      transition: 300ms;
      transform: scale(0.8);
    }

    .swiper-slide-active,
    .swiper-slide-duplicate-active {
      transform: scale(1);
    }
  </style>

</head>

<body>

  <div id="box">

    <myswiper :key="datalist.length">
      <div class="swiper-slide" v-for="data in datalist">
        {{data}}
      </div>
    </myswiper>

  </div>


  <script>
    Vue.component(
      "myswiper",
      {
        template: `
        <div class="swiper-container a">
          <div class="swiper-wrapper">
            <slot></slot>
          </div>

          <!-- 如果需要分页器 -->
          <div class="swiper-pagination"></div>
          </div>
        `,
        mounted() {
          console.log("myswiper mounted");
          new Swiper('.swiper-container', {
            slidesPerView: 3,
            spaceBetween: 30,
            centeredSlides: true,
            loop: true,
            pagination: {
              el: '.swiper-pagination',
              clickable: true,
            },
          });
        }
      }
    )

    new Vue({
      el: "#box",
      data: {
        datalist: []
      },
      mounted() {
        setTimeout(() => {
          this.datalist = [
            "aaa",
            "bbb",
            "ccc",
            "ddd",
            "eee",
            "fff",
            "ggg",
          ]
        }, 2000);
      }
    })

  </script>

</body>

</html>